package net.yambal.android.secretary_alarm.array_adupoter;

import net.yambal.android.geo.fatAddress;
import net.yambal.android.util.StringUtil;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class LiveDoorLocationListArrayAdupter extends ArrayAdapter<fatAddress> {
	private int _textViewResourceId;
	private fatAddress[] _locations;
	private LayoutInflater _inflater;
	
	public LiveDoorLocationListArrayAdupter(Context context, int textViewResourceId, fatAddress[] locations) {
		super(context, textViewResourceId, locations);
		_textViewResourceId = textViewResourceId;
		_locations = locations;
		_inflater = (LayoutInflater)context.getSystemService(
				Context.LAYOUT_INFLATER_SERVICE
		);
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent){
		if(convertView == null){
			convertView = _inflater.inflate(_textViewResourceId, null);
		}
		final fatAddress address = _locations[position];
		if(address != null){
			TextView mTitle = (TextView)convertView.findViewWithTag("textViewLocation");
			if(StringUtil.nullStrig(address.search_key, null)!=null){
				mTitle.setText(address.search_key);
			}else{
				mTitle.setText("?");
			}
		}
		return convertView;
	}
	
	@Override
    public fatAddress getItem(int position) {
      return _locations[position];
    }
	
	@Override
    public int getCount() {
      return _locations.length;
    }
	
	@Override
    public long getItemId(int position) {
      return position;
    }
}
